<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{$cat->cat_name}}-{{$SEO['title']}}</title>
    <meta name="keywords" content="{{$SEO['keywords']}}"/>
    <meta name="description" content="{{$SEO['description']}}"/>
    <!--公用css引用-->
    @include('front.common.style')
    <!--END/公用css引用-->
    <link rel="stylesheet" href="../dist/css/index.css">
</head>
<body>

<!--公共头部-->
@include('front.common.header')
        <!--END/公共头部-->

<!--搜索条件-->

<!--END/搜索条件-->

<?php
function buildSearchLink($filter,$item){
    if(is_array($item)){
        foreach ($item as $k=>$v){
            $filter[$k] = $v;
        }
    }
    return http_build_query($filter);
}
?>


<div class="inbox">
    <div class="filter-wrap">

        <!--已选择搜索条件、统计搜索结果-->
        <ul class="selected">
            <li class="fn-dib"><a href="/">阿福易购</a>&gt; </li>
            @foreach($filterCategory as $k=>$category)
                <li class="fn-dib ">
                    <a href="/cat/{{$category->cat_id}}">
                        {{$category->cat_name}}
                    </a>
                    @if($filterCategory->count()!=($k+1))
                        &gt;
                    @else
                        &nbsp;
                    @endif
                </li>
            @endforeach
        </ul>
        <!--END/已选择搜索条件、统计搜索结果-->

        @if ($filterCat->count()>0)
                <!--搜索条件-->
        <ul class="params-list">
            <li class="param-row">
                <div class="param-tit">分类：</div>
                <ul class="inner-list">
                    @foreach($filterCat as $cat)
                        @if($cat->cat_id == $filter['cat_id'])
                            <li class="item cur"><a href="/cat/{{$cat_id}}?{{buildSearchLink($filter,['cat_id'=>0])}}">{{$cat->cat_name}}&nbsp;({{$catFacet[$cat->cat_id]}})<i class="close">×</i></a></li>
                        @else
                            <li class="item"><a href="/cat/{{$cat_id}}?{{buildSearchLink($filter,['cat_id'=>$cat->cat_id])}}">{{$cat->cat_name}}&nbsp;({{$catFacet[$cat->cat_id]}})</a></li>
                        @endif
                    @endforeach

                </ul>
            </li>
        </ul>
        <!--END/搜索条件-->
        @endif


        {{--@if ($filterBrand->count()>0)--}}
                {{--<!--搜索条件-->--}}
        {{--<ul class="params-list">--}}
            {{--<li class="param-row">--}}
                {{--<div class="param-tit">品牌：</div>--}}
                {{--<ul class="inner-list">--}}
                    {{--@foreach($filterBrand as $brand)--}}
                        {{--@if($brand->brand_id == $filter['brand_id'])--}}
                            {{--<li class="item cur"><a href="/cat/{{$cat_id}}?{{buildSearchLink($filter,['brand_id'=>0])}}">{{$brand->brand_name}}&nbsp;({{$brandFacet[$brand->brand_id]}})<i class="close">×</i></a></li>--}}
                        {{--@else--}}
                            {{--<li class="item"><a href="/cat/{{$cat_id}}?{{buildSearchLink($filter,['brand_id'=>$brand->brand_id])}}">{{$brand->brand_name}}&nbsp;({{$brandFacet[$brand->brand_id]}})</a></li>--}}
                        {{--@endif--}}
                    {{--@endforeach--}}

                {{--</ul>--}}
            {{--</li>--}}
        {{--</ul>--}}
        {{--<!--END/搜索条件-->--}}
        {{--@endif--}}


        <!--排序-->
        <div class="sort">
            <div class="page-num fn-fr"><span class="total-result">共搜索到<span class="text-color-1"> {{$goodsPaginate->total()}} </span>个结果</span><span class="text-color-2">{{$goodsPaginate->currentPage()}}</span>/{{$goodsPaginate->lastPage()}}</div>
            <span class="label">排序：</span>
            <?php ?>
            <span class="J-sort sort-param fn-dib @if ($filter['sort']=='') down @endif" url="/cat/{{$cat_id}}?{{buildSearchLink($filter,['sort'=>''])}}">默认 <i class="icon"></i><i class="icon icon-arrow-t3"></i></span>
            <span class="J-sort sort-param fn-dib @if ($filter['sort']=='sale_desc') down @endif @if ($filter['sort']=='sale_asc') up @endif" url="/cat/{{$cat_id}}?{{buildSearchLink($filter,['sort'=>($filter['sort']=='sale_asc')?'sale_desc':'sale_asc'])}}">销量  <i class="icon icon-arrow-b3"></i> <i class="icon icon-arrow-t3"></i></span>
            <span class="J-sort sort-param fn-dib @if ($filter['sort']=='price_desc') down @endif @if ($filter['sort']=='price_asc') up @endif" url="/cat/{{$cat_id}}?{{buildSearchLink($filter,['sort'=>($filter['sort']=='price_asc')?'price_desc':'price_asc'])}}">价格 <i class="icon icon-arrow-b3"></i> <i class="icon icon-arrow-t3"></i></span>
            <label><input class="J-stock" type="checkbox" @if ($filter['stock']=='1') checked @endif  url="/cat/{{$cat_id}}?{{buildSearchLink($filter,['stock'=>($filter['stock']==1)?0:1])}}">仅显示有货</label>
        </div>
        <!--END/排序-->
    </div>
</div>

@inject('goodsService','App\Interfaces\GoodsService')
@inject('pictureService','App\Interfaces\PictureService')
@inject('shopService','App\Interfaces\ShopService')
@inject('userCollectionService','App\Interfaces\UserCollectionService')

@if ($goodsPaginate->total()>0)
<!--搜索结果-->
<div class="inbox result-list">
    <div class="panel-body">
        <ul class="imglist-2 ui-cols-4 imglist-2-ver imglist-skin-2">
            @foreach($goodsPaginate->getCollection() as $goods)
                <?php
                $goods = $goodsService->get($goods->getFields()['goods_id']);
                $shop= $shopService->get($goods->shop_id);
                $goodsInCollection=isset($user)?$userCollectionService->isInCollection($user->id,'GOODS',$goods->goods_id):false;
                ?>
                    <li class="col col-space">
                        <div class="col-box">
                            <div class="col-l">
                                <a href="/goods/{{$goods->goods_id}}" target="_blank" title="{{$goods->goods_name}}">
                                    <img class="lazy img-lazyload" data-src="{{$pictureService::thumb($goods->goods_thumb,254,254)}}" alt="">
                                </a>

                                @if($goods->goods_number==0)
                                    <i class="icon icon-soldout"></i>
                                @endif
                            </div>
                            <div class="col-r">
                                <div class="panel-body">
                                    @if($goodsInCollection)
                                        <a href="javascript:;" class="fav-link fav"><i class="icon icon-fav"></i>已收藏</a>
                                    @else
                                        <a href="javascript:;" class="J-add-collection fav-link" reference_id="{{$goods->goods_id}}" collection-type="GOODS"><i class="icon icon-noFav"></i>收藏</a>
                                    @endif

                                    <p>
                                        <span class="text-color-1 font-14 fn-mr4">￥<span class="font-24">{{$goods->shop_price}}</span></span>
                                        @if($goods->shop_price>=60)
                                            <span class="bl-label label-brd-red fn-mb8">包邮</span>
                                        @endif
                                        <del class="fn-fr font-14 fn-mt6 fn-hide">￥{{$goods->market_price}}</del>
                                    </p>
                                    <a class="tit link fn-dib-otw ui-100" href="/goods/{{$goods->goods_id}}" target="_blank" title="{{$goods->goods_name}}">{{$goods->goods_name}}</a>
                                    <p class="sub-tit fn-dib-otw" title="{{$goods->goods_pet_name}}">{{$goods->goods_pet_name}}&nbsp;</p>
                                    <p>
                                        @if($shop->shop_name=='阿福易购')
                                            <a href="/shop/{{$goods->shop_id}}" target="_blank">{{$shop->shop_name}}</a><span class="bl-label fn-ml4">自营</span>
                                        @else
                                            <a href="/shop/{{$goods->shop_id}}" target="_blank">{{$shop->shop_name}}旗舰店</a>
                                        @endif
                                    </p>

                                </div>
                            </div>
                        </div>
                    </li>

            @endforeach
        </ul>
        <!--分页-->
        <div class="pager pager-big fn-tc">
        {!! $goodsPaginate->appends($filter)->render() !!}
        </div>

        <!--END/分页-->
    </div>

</div>
<!--END/搜索结果-->
@else

<!--无数据-->
<div class="inbox ui-brd-box1">
    <div class="bl-nodata nodata-imgtext nodata-imgtext-smaller">
        <div class="nodata-img">
            <img src="../images/mascot.png" alt="">
        </div>

        <div class="nodata-text nodata-con nodata-imgtext-small">
            {{--<div class="h1">抱歉，没有找到与“<span class="text-color-1">XXX</span>”相关的商品</div>--}}
            <div class="h1">抱歉，没有找到相关的商品</div>
            <p>建议您：</p>
            <p>1、看看输入的文字是否有误</p>
            <p>2、拆分要搜索的关键词，分成几个词语再次搜索</p>
        </div>
    </div>
</div>
<!--END/无数据-->
@endif


<!--猜你喜欢-->
<?php
    $randomGoods = $goodsService->getRandomGoods(20);
?>
<div class="inbox">
    <div class="js-recommend  recommend-list">
        <div class="list-head fn-mb16">
            <div class="tit tit-4">
                <h3 class="h fn-mr10">
                    猜你喜欢
                </h3>
                <div class="more fn-fl fn-mt4">
                    根据您的浏览记录推荐的商品
                </div>
                <a href="javascript:;" class="js-reloadBtn more" data-step="0"><i class="icon icon-load1"></i>换一批</a>
            </div>
        </div>
        <div class="list-body"  style="height: 268px;">
            <ul class="bl-imglist imglist-5col js-recList ui-100">

                @if($randomGoods)
                    @foreach($randomGoods as $key=>$value)
                        <?php //dd($value->toArray());
                        if($key<2) continue;
                        if($key>17) break;
                        ?>
                        <li style="height: 268px;">
                            <div class="col-space fn-ohide">
                                <a href="/goods/{{$value->goods_id}}" target="_blank" title="{{$value->goods_name}}">
                                    <img class="lazy img-lazyload" style="width: 200px;height: 200px;" data-src="@if($value->goods_thumb){{$pictureService->thumb($value->goods_thumb, 200, 200)}} @else # @endif" alt="">
                                </a>
                                <div class="fn-ml4 fn-mr4">
                                    <a href="/goods/{{$value->goods_id}}" target="_blank" class="name ui-100 fn-dib-otw" title="{{$value->goods_name}}">{{$value->goods_name}}</a>
                                    <p class="price"><span>{{$value->shop_price}}</span>元</p>
                                </div>
                            </div>
                        </li>
                    @endforeach
                @endif
            </ul>
        </div>
    </div>
</div>
<!--END/猜你喜欢-->


<!--公共尾部-->
@include('front.common.footer')
<!--END/公共尾部-->


<!--公用js引用-->
@include('front.common.script')
<!--END/公用js引用-->

<script>
$('.js-moreBtn').click(function(){
    var that =$(this),
        list=that.siblings('.inner-list');
    that.toggleClass('open');
    list.css('max-height',that.hasClass('open')?'none':'60px');
    list.css('*height',that.hasClass('open')?'auto':'32px');
});
</script>

<script type="text/javascript">

    $('.sort-param').click(function(e){
        var item = $(e.currentTarget);
        var url = item.attr('url');
        window.location.href=url;
    });
    $('.J-stock').change(function(e){
        var item = $(e.currentTarget);
        var url = item.attr('url');
        window.location.href=url;
    });

</script>
</body>
</html>